<template>
	<view class="cart-contain" v-if="cart.length!=0">
		<!-- 点击收货地址 -->
		<my_address></my_address>
		<!-- 购物车标题 -->
		<view class="cart-title">
			<uni-icons type="shop" size="18"></uni-icons>
			<text class="title-desc">购物车</text>
		</view>
		<!-- 循环渲染购物车商品数据 -->
		<uni-swipe-action>
			<block v-for="(item,index) in cart" :key="index">
				<uni-swipe-action-item :right-options="options" @click="bindClick(index)">
					<my-goods :goods="item" :isshow="true" :isshownum="true" @readio-change="radioChangehandler"
					@num-change = "numberchangehandler"></my-goods>
				</uni-swipe-action-item>
			</block>
		</uni-swipe-action>
		<my-settle></my-settle>
	</view>
	<view class="nogoods" v-else>
		<image src="/static/other/emtycart.png" mode=""></image>
		<text class="nogoods_title">空空如也</text>
	</view>
</template>

<script>
	import badge from '@/mixins/tabbar-badge.js'
	import {mapState,mapMutations} from 'vuex'
	import mySettle from '@/components/my-settle/my-settle'
	export default {
		mixins:[badge],
		data() {
			return {
				options:[ {
					text: '删除',
					style: {
					  backgroundColor: '#c00000'
				            }
				      }],
				address:{}
			}
		},
		computed:{
			...mapState('m_cart',['cart'])
		},
		components:{
			mySettle
		},
		methods:{
			...mapMutations('m_cart',['updatagoodsstate','updatagoodscount','delgoodsinfo']),
			radioChangehandler(e){
				console.log(e)
				this.updatagoodsstate(e)
			},
			// 购物车商品加一和减一监听
			numberchangehandler(e){
				this.updatagoodscount(e)
			},
			// 点击了删除按钮
			bindClick(e){
				this.delgoodsinfo(e)
			}
		}
		
		
		
	}
</script>

<style>
	.cart-contain{
		padding-bottom: 50px;
	}
.cart-title{
	display: flex;
	padding:  5px;
	align-items: center;
	border-bottom: 1px solid #ccc;
}
.title-desc{
	margin-left: 5px;
}
.address{
	padding: 15px 0px;
	box-sizing: border-box;
	border-bottom: 1px solid #c05230;
	box-shadow: 1px 1px 1px #c02b93;
	
}
.showaddress{
	padding: 5px;
	display: flex;
	line-height: 2em;
	font-size: 14px;
	flex-direction: column;
	
}
.btnaddress{
	left: 50%;
	transform: translateX(-50%);
}
.row-1{
	display: flex;
	justify-content: space-between;
}
.row-1 .phone text{
	margin: 5px;
}
.row-1 .name{
	width: 40%;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
}
.row-2{
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
}
.nogoods{
	display: flex;
	height: 100%;
	width: 100%;
	text-align: center;
	justify-content: center;
	align-items: center;
	flex-direction: column;
}
.nogoods image{
	width: 90px;
	height: 90px;
	margin-top: 100px;
	margin-bottom: 10px;
}
.nogoods_title{
	color: grey;
	font-size: 12px;
	margin: 4px;
}
</style>
